import click
from frappe.desk.page.setup_wizard.setup_wizard import make_records


def after_install():
	try:
		print("Setting up Raven...")
		create_general_channel()

		click.secho("Thank you for installing Raven!", fg="green")

	except Exception as e:
		BUG_REPORT_URL = "https://github.com/The-Commit-Company/Raven/issues/new"
		click.secho(
			"Installation for Raven failed due to an error."
			" Please try re-installing the app or"
			f" report the issue on {BUG_REPORT_URL} if not resolved.",
			fg="bright_red",
		)
		raise e


def create_general_channel():
	channel = [
		{"doctype": "Raven Channel", "name": "general", "type": "Open", "channel_name": "General"}
	]

	make_records(channel)
